<?php
namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Services\SoapService;
use App\Services\TJSoapService;

class SoapCallbackController extends Controller
{
    //soap服务端，默认已有wsdl，直接setClass
    public function soapFun()
    {
        //header('Content-Type:text/xml;charset=utf-8');
        ini_set('soap.wsdl_cache','0');
        ini_set('soap.wsdl_cache_ttl','0');
        ini_set('soap.wsdl_cache_enabled', "0");
        try {
            $procClass     = '\App\Services\SoapService';
            $classNameFull = explode('\\', $procClass);
            $className     = array_pop($classNameFull);
            $storagePath   = storage_path();
            if (! file_exists($storagePath . '/wsdl/' . $className . '.wsdl')) {
                if (! file_exists($storagePath . '/wsdl/')) {
                    mkdir($storagePath . '/wsdl/', 0777, true);
                }
                require_once app_path() . '/Libs/SoapDiscovery.php';

                $soapDiscovery = new \SoapDiscovery($procClass, 'SoapServicePHP');
                $file          = fopen($storagePath . '/wsdl/' . $className . '.wsdl', 'w');
                fwrite($file, $soapDiscovery->getWSDL());
                fclose($file);
            }
            $server = new \SoapServer($storagePath . '/wsdl/' . $className . '.wsdl', array('soap_version' => SOAP_1_2));
            $server->setClass($procClass);
            $server->handle();
        } catch (\Exception $e) {
            info('wsdl服务创建异常'.$e->getMessage());
        }
    }
    //soap服务端，默认已有wsdl，直接setClass
    public function TjsoapFun()
    {
        //header('Content-Type:text/xml;charset=utf-8');
        ini_set('soap.wsdl_cache','0');
        ini_set('soap.wsdl_cache_ttl','0');
        ini_set('soap.wsdl_cache_enabled', "0");
        try {
            $procClass     = '\App\Services\TjSoapService';
            $classNameFull = explode('\\', $procClass);
            $className     = array_pop($classNameFull);
            $storagePath   = storage_path();
            if (! file_exists($storagePath . '/wsdl/' . $className . '.wsdl')) {
                if (! file_exists($storagePath . '/wsdl/')) {
                    mkdir($storagePath . '/wsdl/', 0777, true);
                }
                require_once app_path() . '/Libs/SoapDiscovery.php';

                $soapDiscovery = new \SoapDiscovery($procClass, 'SoapServicePHP');
                $file          = fopen($storagePath . '/wsdl/' . $className . '.wsdl', 'w');
                fwrite($file, $soapDiscovery->getWSDL());
                fclose($file);
            }
            $server = new \SoapServer($storagePath . '/wsdl/' . $className . '.wsdl', array('soap_version' => SOAP_1_2));
            $server->setClass($procClass);
            $server->handle();
        } catch (\Exception $e) {
            info('wsdl服务创建异常'.$e->getMessage());
        }
    }

}
